package org.mozhu.mboot.core.i18n;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

import javax.validation.Validator;
import javax.validation.executable.ExecutableValidator;

@Configuration
@ConditionalOnClass(ExecutableValidator.class)
public class ValidationAutoConfiguration {

    @Bean
    public Validator validator(MessageSource messageSource) throws Exception {
        LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
        validator.setValidationMessageSource(messageSource);
        return validator;
    }

}
